package vg.modules.new_graph_model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;

import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import vg.services.main_manager.MainManager;
import vg.services.plugin_manager.event_and_request.event.UIEventOpenNewGraph;
import vg.services.plugin_manager.interfaces.IPlugin;
import vg.services.plugin_manager.realization.PluginParameter;
import vg.services.user_interface_manager.interfaces.AMenuItem;

public class NewGraphModelPlugin implements IPlugin {
	@Override
	public void install(final PluginParameter pluginParameter) throws Exception {
		// initialize components
		JMenuItem export2GraphMLMenuItem = new JMenuItem("New graph model"); 

		// initialize listeners
		export2GraphMLMenuItem.addActionListener(new ActionListener() {		
			public void actionPerformed(ActionEvent e) {
				String graph_model_name = (String) JOptionPane.showInputDialog(
								pluginParameter.userInterface.getMainFrame(),
								"Select graph model:", "Select dialog",
								JOptionPane.PLAIN_MESSAGE, null,
								null, null);
				
				int graphModelId = MainManager.model.createGraphModelHeaderWithEmptyRootGraph(graph_model_name);				
				if (graphModelId >= 0)
					MainManager.view.addEvent(new UIEventOpenNewGraph(graphModelId, graph_model_name));
			}
		});
		
		pluginParameter.userInterface.addMenuItem(new AMenuItem(export2GraphMLMenuItem) {
			public void update(Observable o, Object arg) {}
		}, "File");			
	}
}
